<template>
    <div id="left">
        <h3>这是左边</h3>
        <div>初始值init输入的是{{ count }}</div>
        <button @click="add">+1</button>
        <div>右边的值是{{ rightCount }}</div>
    </div>
</template>
  
<script>
import eventBus from './eventBus.js'
  export default {
    props:['init'],
    data() {
      return {
        count:this.init,
        rightCount:0
      }
    },
    methods: {
      add(){
        this.count++
        this.$emit('add',this.count)
        eventBus.$emit('share',this.count)
      },
    },
    created(){
        eventBus.$on('share1',val=>{
          this.rightCount=val
        })
    },
    watch:{},
    computed:{},
    filters:{},
  }
</script>
  
<style lang="less">
#left {
    width: 50%;
    height: 200px;
    background-color: red;
    color: black;
}
</style>